<?php if (!defined('THINK_PATH')) exit(); /*a:4:{s:78:"E:\web\project\baojia\wwwww\public/../application/admin\view\mukuai\gedit.html";i:1537078561;s:70:"E:\web\project\baojia\wwwww\application\admin\view\layout\default.html";i:1529292885;s:67:"E:\web\project\baojia\wwwww\application\admin\view\common\meta.html";i:1535990037;s:69:"E:\web\project\baojia\wwwww\application\admin\view\common\script.html";i:1533222223;}*/ ?>
<!DOCTYPE html>
<html lang="<?php echo $config['language']; ?>">
    <head>
        <meta charset="utf-8">
<title><?php echo (isset($title) && ($title !== '')?$title:''); ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit">

<link rel="shortcut icon" href="/public/assets/img/favicon.ico" />
<!-- Loading Bootstrap -->
<link href="/public/assets/css/backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.css?v=<?php echo \think\Config::get('site.version'); ?>" rel="stylesheet">
<link href="/public/assets/js/uploadify/uploadify.css" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. -->
<!--[if lt IE 9]>
  <script src="/public/assets/js/html5shiv.js"></script>
  <script src="/public/assets/js/respond.min.js"></script>
<![endif]-->
<script type="text/javascript">
    var require = {
        config:  <?php echo json_encode($config); ?>
    };
</script>
<script src="/public/assets/libs/jquery/dist/jquery.min.js"></script>
<script src="/public/assets/js/uploadify/jquery.uploadify.min.js"></script>
    </head>

    <body class="inside-header inside-aside <?php echo defined('IS_DIALOG') && IS_DIALOG ? 'is-dialog' : ''; ?>">
        <div id="main" role="main">
            <div class="tab-content tab-addtabs">
                <div id="content">
                    <div class="row">
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                            <section class="content-header hide">
                                <h1>
                                    <?php echo __('Dashboard'); ?>
                                    <small><?php echo __('Control panel'); ?></small>
                                </h1>
                            </section>
                            <?php if(!IS_DIALOG && !$config['fastadmin']['multiplenav']): ?>
                            <!-- RIBBON -->
                            <div id="ribbon">
                                <ol class="breadcrumb pull-left">
                                    <li><a href="dashboard" class="addtabsit"><i class="fa fa-dashboard"></i> <?php echo __('Dashboard'); ?></a></li>
                                </ol>
                                <ol class="breadcrumb pull-right">
                                    <?php foreach($breadcrumb as $vo): ?>
                                    <li><a href="javascript:;" data-url="<?php echo $vo['url']; ?>"><?php echo $vo['title']; ?></a></li>
                                    <?php endforeach; ?>
                                </ol>
                            </div>
                            <!-- END RIBBON -->
                            <?php endif; ?>
                            <div class="content">
                                <form id="add-form" class="form-horizontal" method="POST" action="<?php echo url('gsave'); ?>">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">功能名称:</label>
        <div class="col-xs-12 col-sm-8">
            <input type="text" name="name" value="<?php echo (isset($data['name']) && ($data['name'] !== '')?$data['name']:''); ?>" class="form-control"/>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">所属模块:</label>
        <div class="col-xs-12 col-sm-8">
            <select class="form-control" name="model_id" id="model_id" >
                 <option value="0">请选择</option>
                <?php if(is_array($models) || $models instanceof \think\Collection || $models instanceof \think\Paginator): $i = 0; $__LIST__ = $models;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>  

                <option value="<?php echo $vo['id']; ?>" <?php if(((!empty($data)) AND $data['model_id'] == $vo['id']) OR ($vo['id'] == $model_id)): ?>selected<?php endif; ?>><?php echo $vo['name']; ?></option>
               <?php endforeach; endif; else: echo "" ;endif; ?> 
            </select>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">功能清单:</label>
    </div>
    <div class="my-copy-body">
        <div class="my-body" id="child_list">
        <?php if(!(empty($child) || (($child instanceof \think\Collection || $child instanceof \think\Paginator ) && $child->isEmpty()))): if(is_array($child) || $child instanceof \think\Collection || $child instanceof \think\Paginator): $i = 0; $__LIST__ = $child;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?>    
            <div class="form-group child">
                <label class="control-label col-xs-12 col-sm-2"></label>
                <div class="col-xs-12 col-sm-8"  style="background-color: #fff;padding-top: 15px;">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">名称:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="text" class="form-control" name="cname" value="<?php echo $vo['cname']; ?>"  />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">应用:</label>
                        <div class="col-xs-12 col-sm-8">
                            <?php $vo['type_id']=explode(',',$vo['type_id']); if(is_array($type) || $type instanceof \think\Collection || $type instanceof \think\Paginator): $i = 0; $__LIST__ = $type;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ch): $mod = ($i % 2 );++$i;?>
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><?php echo $ch['name']; ?><input style="position: relative;top: 2px;" name="type_id[]" <?php if((!empty($vo)) AND in_array($ch['id'],$vo['type_id'])): ?>checked<?php endif; ?> value="<?php echo $ch['id']; ?>" type="checkbox">
                            </label>
                           <?php endforeach; endif; else: echo "" ;endif; ?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">说明:</label>
                        <div class="col-xs-12 col-sm-8">
                            <textarea type="text" name="des" class="form-control"><?php echo (isset($vo['des']) && ($vo['des'] !== '')?$vo['des']:''); ?></textarea>
                        </div>
                    </div>
                    <input type="hidden" name="cid" value="<?php echo (isset($vo['id']) && ($vo['id'] !== '')?$vo['id']:''); ?>" />
                </div>

            </div>
         <?php endforeach; endif; else: echo "" ;endif; else: ?>
          <div class="form-group child">
                <label class="control-label col-xs-12 col-sm-2"></label>
                <div class="col-xs-12 col-sm-8"  style="background-color: #fff;padding-top: 15px;">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">名称:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="text" class="form-control" name="cname"   />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">应用:</label>
                        <div class="col-xs-12 col-sm-8">
                           <?php if(is_array($type) || $type instanceof \think\Collection || $type instanceof \think\Paginator): $i = 0; $__LIST__ = $type;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ch): $mod = ($i % 2 );++$i;?>   
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><?php echo $ch['name']; ?><input style="position: relative;top: 2px;" name="type_id[]" 
                             value="<?php echo $ch['id']; ?>" type="checkbox">
                            </label>
                          <?php endforeach; endif; else: echo "" ;endif; ?>   
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">说明:</label>
                        <div class="col-xs-12 col-sm-8">
                            <textarea type="text" name="des" class="form-control"></textarea>
                        </div>
                    </div>
                    <input type="hidden" name="cid" value="" />
                </div>

            </div>
       <?php endif; ?>

        </div>
    </div>
    <div style="text-align: center;margin-bottom: 15px;">
        <button type="button" class="btn btn-success copy">添加更多</button>
        <button type="button" class="btn btn-success copy-del">删除一个</button>
    </div>
    <div id="my-copy-box"></div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <input type="hidden" name="id" value="<?php echo (isset($data['id']) && ($data['id'] !== '')?$data['id']:''); ?>" />
            <button type="submit" id="submit" class="btn btn-success"><?php echo __('OK'); ?></button>
        </div>
    </div>
</form>

<div id="template" style="display: none;">
     <div class="form-group child">
                <label class="control-label col-xs-12 col-sm-2"></label>
                <div class="col-xs-12 col-sm-8"  style="background-color: #fff;padding-top: 15px;">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">名称:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="text" class="form-control" name="cname"   />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">应用:</label>
                        <div class="col-xs-12 col-sm-8">
                           <?php if(is_array($type) || $type instanceof \think\Collection || $type instanceof \think\Paginator): $i = 0; $__LIST__ = $type;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ch): $mod = ($i % 2 );++$i;?>   
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><?php echo $ch['name']; ?><input style="position: relative;top: 2px;" name="type_id[]" 
                             value="<?php echo $ch['id']; ?>" type="checkbox">
                            </label>
                          <?php endforeach; endif; else: echo "" ;endif; ?>   
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">说明:</label>
                        <div class="col-xs-12 col-sm-8">
                            <textarea type="text" name="des" class="form-control"></textarea>
                        </div>
                    </div>
                    <input type="hidden" name="cid" value="" />
                </div>

            </div>
</div>

<script>
    $(function(){
        $(".copy").click(function(){
           var child_dom=$("#template").html();
           $("#child_list").append(child_dom);
        });
         $(".copy-del").click(function(){
            $("#child_list").find(".child").eq(-1).remove();
        });
        $("#submit").click(function(){
             var items = new Array();
             var cheklist=$("#child_list").find(".child");
              for (var i = 0; i < cheklist.length; i++) {
                    var child_box=$(cheklist[i]);
                    var cname=child_box.find("input[name=cname]").val();
                    var des=child_box.find("[name=des]").val();
                    var cid=child_box.find("input[name=cid]").val();
                    var type_id='';

                    $.each(child_box.find('input[name="type_id[]"]:checked'),function(){
                        type_id+=$(this).val()+',';
                    });
                  var item= {id:cid,cname: cname, des: des,type_id:type_id};
                 items.push(item);
            }
           var child=JSON.stringify( items );

           var name=$("input[name=name]").val();
           var model_id=$("#model_id").val();
           var id=$("input[name=id]").val();
           $.ajax({
                    type:'POST',
                    data:{
                        child:child,
                        id:id,
                        name:name,
                        model_id:model_id,
                    },
                    url:"<?php echo url('gsave'); ?>",
                    traditional: true,
                    success:function(data){                            
                          if(data.code==1){
                            alert(data.msg);
                            window.location.href=data.url;
                          }else{
                            alert(data.msg);
                          }
                    }
            });   
            return false;        
        });

    })
</script>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        
<script src="/public/assets/js/require<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js" data-main="/public/assets/js/require-backend<?php echo \think\Config::get('app_debug')?'':'.min'; ?>.js?v=<?php echo $site['version']; ?>"></script>
    </body>
</html>